<template>
  <div>
    <el-dialog title="选择收发货人" v-model="show" append-to-body>
      <el-form :model="query" :inline="true" class="form">
        <el-form-item>
          <el-input v-model="query.title" placeholder="请输入"> </el-input>
        </el-form-item>
        <el-form-item style="margin-left: 8px">
          <el-button type="primary" @click="search"> 搜索 </el-button>
        </el-form-item>
      </el-form>
      <AppPageTable
        stripe
        :data="tableData.data"
        @change="getTableData()"
        :autostyle="'height: calc(100% - 81px);'"
        :option="tableData.option"
      >
        <el-table-column prop="entName" label="客户简称" />
        <el-table-column prop="notifyTitle" label="通知人" />
        <el-table-column prop="receiverTitle" label="收货人" />
        <el-table-column prop="shiperTitle" label="发货人" />
        <el-table-column label="操作" width="90px" fixed="right">
          <template #default="scope">
            <el-button @click="choose(scope.row)" link type="primary"
              >选取</el-button
            >
          </template>
        </el-table-column>
      </AppPageTable>
    </el-dialog>
  </div>
</template>

<script>
import { defineComponent } from 'vue'
import AppSearchForm from '@/components/AppSearchForm.vue'
import AppPageTable, { useTableOption } from '@/components/AppPageTable2'
export default defineComponent({
  components: {
    AppPageTable,
    AppSearchForm
  },
  emits: ['choose'],
  data() {
    return {
      show: false,
      tableData: {
        data: [],
        option: useTableOption({
          pageSize: 15,
          pageSizes: [10, 15, 50, 100]
        })
      },
      query: {
        title: ''
      },
      entID: ''
    }
  },
  methods: {
    open(id) {
      this.show = true
      this.entID = id
      this.$nextTick(() => {
        this.getTableData()
      })
    },
    getTableData() {
      this.tableData.option.loading = true
      this.$http
        .get('/api/bubltitle/query', {
          Title: this.query.title,
          EntId: this.entID,
          PageIndex: this.tableData.option.page,
          PageSize: this.tableData.option.pageSize
        })
        .then((res) => {
          this.tableData.data = res.content
          this.tableData.option.total = res.totalElements
        })
        .finally(() => {
          this.tableData.option.loading = false
        })
    },
    search() {
      this.tableData.option.page = 1
      this.getTableData()
    },
    choose(data) {
      this.$emit('choose', data)
      this.show = false
    }
  },
  mounted() {}
})
</script>

<style lang="scss" scoped>
.form {
  margin-bottom: 8px;
  height: 24px;
  //   :deep(.el-form-item) {
  //     width: auto !important;
  //   }
}
</style>
